import { defineStore } from "pinia";
import { getPointApi } from "../apis/user";

export const useUserStore = defineStore('user', {
    state: () => ({ userid: 0, points: 0, name: '###' }),
    getters: {
        getUserId: (state): number => {
            return state.userid
        },
        getPoints: (state): number => {
            return state.points
        },
        getName: (state): string => {
            return state.name
        }
    },
    actions: {
        setUserId(userId: number) {
            this.userid = userId
        },
        setPoints(points: number) {
            this.points = points
        },
        setUserName(name: string) {
            this.name = name
        },
        async updatePoint() {
            const res = await getPointApi(this.userid)
            if (res.status === 200) {
                this.setPoints(res.data.point)
            }
        }
    }
})